<div class="layui-fluid" id="VIEW-list-table" lay-title="字典项" lig-title="dict-title">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-row layui-col-space30">
                <div class="layui-col-md4" style="border-right: 1px solid #e2e2e2;">
                    <div lay-filter="lig-dict-tree"></div>
                </div>
                <div class="layui-col-md8">
                    <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
                        <form lay-filter="lig-dict-searchform">
                            <input type="hidden" name="parentId"/>
                        </form>
                        <div class="layui-btn layui-btn-sm" lay-filter="lig-dict-add" lig-lang="btn-addDictChild">添加子项</div>
                    </div>
                    <table lay-filter="lig-dict-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="tpl-row-toolBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="lig-modify" lay-filter="lig-dict-modify" lig-lang="btn-modify">修改</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="lig-delete" lay-filter="lig-dict-delete" lig-lang="btn-delete">删除</a>

</script>
<script type="text/html" id="tpl-dict-modify">
    <form class="layui-form" style="padding: 20px 20px 0 0;" lay-filter="lig-saveForm">
        <input type="hidden" name="dictId" value="{{d.dictId}}"/>
        <div class="layui-form-item">
            <label class="layui-form-label ligui-form-item-required" lig-lang="dict-dictName">名称</label>
            <div class="layui-input-block">
                <input type="text" name="dictName" lay-verify="required" autocomplete="off" class="layui-input"
                       value='{{d.dictName}}'>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input type="text" name="serial" autocomplete="off"
                       class="layui-input" value="{{d.serial}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" lig-lang="dict-dictValue">扩展值</label>
            <div class="layui-input-block">
                <input type="text" name="dictValue" autocomplete="off"
                       class="layui-input" value="{{d.dictValue}}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" lig-lang="dict-constant">代码</label>
            <div class="layui-input-block">
                <input type="text" autocomplete="off" disabled
                       class="layui-input" value="{{d.constant}}">
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="tpl-dict-add">
    <form class="layui-form" style="padding: 20px 20px 0 0;" lay-filter="lig-saveForm">
        <input type="hidden" name="parentId"/>
        <div class="layui-form-item">
            <label class="layui-form-label ligui-form-item-required" lig-lang="dict-dictName">名称</label>
            <div class="layui-input-block">
                <input type="text" name="dictName" lay-verify="required" autocomplete="off" class="layui-input"
                       value=''>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">序号</label>
            <div class="layui-input-block">
                <input type="text" name="serial" autocomplete="off"
                       class="layui-input" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" lig-lang="dict-dictValue">扩展值</label>
            <div class="layui-input-block">
                <input type="text" name="dictValue" autocomplete="off"
                       class="layui-input" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" lig-lang="dict-constant">代码</label>
            <div class="layui-input-block">
                <input type="text" name="constant" autocomplete="off"
                       class="layui-input" value="">
            </div>
        </div>
    </form>
</script>

<script>
    layui.use(['jquery', 'form', 'eleTree', 'lig'], function ($, form, eleTree, lig) {
        form.render();

        var _dataTable = lig.table({
            elem: '[lay-filter="lig-dict-table"]',
            url: 'setting/dict/page',
            cols: [[
                { title: '<span lig-lang="label-opt">操作</span>', toolbar: '#tpl-row-toolBar', align: 'left', width: 120, fixed: 'left'},
                { title: '<span lig-lang="dict-dictName">名称</span>', field: 'dictName', minWidth: 150 },
                { title: '<span lig-lang="dict-dictCode">编码</span>', field: 'dictCode', minWidth: 100 },
                { title: '<span lig-lang="dict-serial">序号</span>', field: 'serial', minWidth: 60 },
                { title: '<span lig-lang="dict-dictValue">扩展值</span>', field: 'dictValue', minWidth: 100 },
                { title: '<span lig-lang="dict-constant">代码</span>', field: 'constant', minWidth: 100 },
            ]]
        },{
            mode: 'dialog',
            entity: 'dict',
            primaryField: 'dictId',
            addContent: $('#tpl-dict-add').html(),
            addUrl: 'setting/dict/add',
            addTitle: '<span lig-lang="dict-addDictChild">添加子项</span>',
            area: ['50%', 'auto'],
            onAddOpened: function() {
                $('[lay-filter="lig-saveForm"]').find('input[name="parentId"]').val($('[lay-filter="lig-dict-searchform"]').find('input[name="parentId"]').val());
            },

            modifyContent: $('#tpl-dict-modify').html(),
            modifyUrl: 'setting/dict/modify',
            modifyTitle: '<span lig-lang="dict-modifyDict">修改字典项</span>',
            area: ['50%', 'auto'],

            removeUrl: 'setting/dict/remove',
            getUrl: 'setting/dict/{dictId}'
        });

        lig.ajaxget({
            url: 'setting/dict/tree',
            success: function (res) {
                eleTree.render({
                    elem: '[lay-filter="lig-dict-tree"]',
                    highlightCurrent: true,
                    showLine: true,
                    expandOnClickNode: false,
                    defaultExpandedKeys: ['root'],
                    data: res.data,
                    request: {
                        name: "title"
                    }
                });
                // 节点点击事件
                eleTree.on("nodeClick(lig-dict-tree)",function(d) {
                    $('[lay-filter="lig-dict-searchform"]').find('input[name="parentId"]').val(d.data.currentData.id);
                    _dataTable.reloadTable();
                })
            }
        });
    });
</script>